package com.rock.code.bigdata.settingkpi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.common.pager.Page;
import com.rock.code.common.comm.RandomGUID;
import com.rock.code.bigdata.settingkpi.dao.TbCdeKpiDao;
import com.rock.code.bigdata.settingkpi.domain.TbCdeKpi;
import com.rock.code.bigdata.settingkpi.service.TbCdeKpiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * kpi列表 Service 实现
 *
 * @author shijian
 * @date 2018/10/10
 */
@Service
public class TbCdeKpiServiceImpl extends BaseServiceImpl<TbCdeKpiDao> implements TbCdeKpiService {

    @Resource
    private TbCdeKpiDao tbCdeKpiDao;

    /**
     * Insert.
     *
     * @param tbCdeKpi the TbCdeKpi
     * @return the int
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public int insert(TbCdeKpi tbCdeKpi) throws Exception {
        tbCdeKpi.setKpiId(RandomGUID.getRandomGUID());
        return tbCdeKpiDao.insert(tbCdeKpi);
    }

    /**
     * Delete.
     *
     * @param primaryKey the primary key
     * @return the int
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public int delete(String primaryKey) throws Exception {
        return tbCdeKpiDao.delete(primaryKey);
    }

    /**
     * Delete by param.
     *
     * @param param the param
     * @return the int
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public int deleteByParam(Map<String, Object> param) throws Exception {
        return tbCdeKpiDao.deleteByParam(param);
    }

    /**
     * Update.
     *
     * @param tbCdeKpi the TbCdeKpi
     * @return the int
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public int update(TbCdeKpi tbCdeKpi) throws Exception {
        return tbCdeKpiDao.update(tbCdeKpi);
    }

    @Override
    public TbCdeKpi query(TbCdeKpi tbCdeKpi) throws Exception {
        return tbCdeKpiDao.query(tbCdeKpi);
    }

    /**
     * Query by para map.
     *
     * @param param the param
     * @return the tbCdeKpi
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public TbCdeKpi queryByParaMap(Map<String, Object> param) throws Exception {
        return tbCdeKpiDao.queryByParaMap(param);
    }

    /**
     * Query list.
     *
     * @param tbCdeKpi the TbCdeKpi
     * @return the list
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public List<TbCdeKpi> queryList(TbCdeKpi tbCdeKpi) throws Exception {
        return tbCdeKpiDao.queryList(tbCdeKpi);
    }

    /**
     * Query list by para map.
     *
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public List<TbCdeKpi> queryListByParaMap(Map<String, Object> param) throws Exception {
        return tbCdeKpiDao.queryListByParaMap(param);
    }

    /**
     * Query page list.
     *
     * @param param the param
     * @return the page info
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    @Override
    public PageInfo queryPageList(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        PageHelper.startPage(page.getPage(), page.getRows());
        if (!orderBy.equals("")) {
            PageHelper.orderBy(orderBy);
        }
        List<TbCdeKpi> list = tbCdeKpiDao.queryListByParaMap(param);
        return new PageInfo(list);
    }

     /**
     * Query list by order.
     *
     * @param page  the page
     * @param param the param
     * @return the list
     * @throws Exception the exception
     * @author shijian
     * @date 2018/10/10
     */
    public List<TbCdeKpi> queryListByOrder(Page page, Map<String, Object> param) throws Exception {
        String orderBy = "";
        if (!StringUtil.isEmpty(page.getSidx())) {
            orderBy = this.getOrderBy(page);
        }
        if (!orderBy.equals("")) {
            param.put("orderBy", orderBy);
        }
        return tbCdeKpiDao.queryListByParaMap(param);
    }

}